<?php
class Model_User extends MY_Model
{
    const DB_TABLE='user';
    const DB_TABLE_PK='id';
    
    public $id;
    public $user_type_id;
    public $first_name;
    public $last_name;
    public $business_name;
    public $user_name;
    public $email;
    public $tel;
    public $password;
    public $active;
    
    public function getlist() {
        return $query =$this->db->query("select 
                                   u.*,
                                   t.name as user_type_name
                           from user u
                           inner join user_type t on u.user_type_id =t.id
                           where u.active=1");
    }
    
    public function getsearch($search,$user_type_id) {
        
        return $query =$this->db->query(" 
                        select 
                                u.*,
                                t.name as user_type_name
                        from user u
                        inner join user_type t on u.user_type_id =t.id
                        where u.active=1 and (u.user_name like '%".$search."%' or 
                        u.first_name like '%".$search."%' or u.last_name like '%".$search."%')
                        and (".$user_type_id." =0 or t.id =".$user_type_id.")");
    }
     
}
